/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gblend.db;


import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import org.jdesktop.application.ResourceMap;
import gblend.GBlendApp;
import gblend.GBlendView;

/**
 *
 * @author cjjin
 */
class NodeCellRenderer extends DefaultTreeCellRenderer {

    private ImageIcon _openIcon;
    private ImageIcon _closedIcon;
    private ImageIcon _leafIcon;
    private ImageIcon dataSourceNodeIcon;
    private ResourceMap resourceMap;
    //private LoadSchema  schema;
    public NodeCellRenderer() {
        resourceMap =
                GBlendApp.getApplication().getContext().getResourceMap(GBlendView.class);
        _openIcon = resourceMap.getImageIcon("SchemaTree.openIcon");
        //_closedIcon = resourceMap.getImageIcon("SchemaTree.dataSourceIcon");
        //_leafIcon = resourceMap.getImageIcon("SchemaTree.openIcon");
        _closedIcon = resourceMap.getImageIcon("SchemaTree.closedIcon");
        _leafIcon = resourceMap.getImageIcon("SchemaTree.leafIcon");
        dataSourceNodeIcon = resourceMap.getImageIcon("SchemaTree.dataSourceIcon");
    }
    
    @Override
    public Icon getClosedIcon() {
        return _closedIcon;
    }

    @Override
    public Icon getLeafIcon() {
        return _leafIcon;
    }

    @Override
    public Icon getOpenIcon() {
        return _openIcon;
    }

    @Override
    public Component getTreeCellRendererComponent(
            JTree tree,
            Object value,
            boolean sel,
            boolean expanded,
            boolean leaf,
            int row,
            boolean hasFocus) {
        super.getTreeCellRendererComponent(
                tree,
                value.toString().trim(),
                sel,
                expanded,
                leaf,
                row,
                hasFocus);
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
        
        if(LoadSchema.isDatasource(node)){
            super.setFont(new Font("Tahoma", 1, 12));
            //super.setForeground(Color.ORANGE);
            super.setIcon(dataSourceNodeIcon);
            
            if(sel){
                super.setOpaque(true);
                super.setBackground(Color.PINK);
            }
            else{
                super.setOpaque(false);
            }
        }else{
            super.setOpaque(false);
            super.setFont(new Font("Tahoma", 0, 12));
        }

        return this;
    }
    }
